package com.unj.dubbotest.main;

import java.util.List;
import java.util.concurrent.Future;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.rpc.RpcContext;
import com.ax.dubboxtest.entity.User;
import com.ax.dubboxtest.service.RestApiService;

public class Restful_Test {

	public static void main(String[] args) throws Exception {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				new String[] { "spring-config_restapi-consumer.xml" });
		context.start();
		RestApiService restApiService = (RestApiService) context.getBean("restApiService"); // 获取远程服务代理
		String hello = restApiService.sayHello("1001", "张三");// 执行远程方法
		System.out.println(hello);
		
		RestApiService restApiService2 = (RestApiService) context.getBean("restApiService2"); // 获取远程服务代理
		//String hello2 = restApiService2.sayHello("1001", "张三");// 执行远程方法
		//System.out.println(hello2);
		List<User> list2=restApiService2.getUsers();
		for (User user : list2) {
			System.out.println(user);
		}
		User user=restApiService2.findbyId(12);
		System.out.println(user+"-----1");
		Future<User> barFuture=RpcContext.getContext().getFuture();
		user=barFuture.get();
		System.out.println(user+"-----2");
		//restApiService2.save(new User());
		System.in.read(); // 为保证服务一直开着，利用输入流的阻塞来模拟

		
		// http://127.0.0.1:8880/demo/asd/12
		// http://127.0.0.1:8880/demo/getUsers.json
	}
}